package com.xhwl.centiotdata.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.centiotdata.service.IAttendanceService;
import com.xhwl.centiotdata.suppliersystem.welink.IAttendanceApi;
import com.xhwl.centiotdata.suppliersystem.welink.pojo.AttendanceQuery;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.pedes.AttendanceRecord;
import com.xhwl.common.query.cent.pedes.AttendanceRecordQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: luyi
 * @Description:
 * @Date: Create in 9:51 2021/11/19
 */
@Service
public class AttendanceServiceImpl implements IAttendanceService {

	@Autowired
	private IAttendanceApi attendanceApi;

	private static final Logger log = LoggerFactory.getLogger(AttendanceServiceImpl.class);

	@Override
	public Page<AttendanceRecord> recordList(AttendanceRecordQuery attendanceRecordQuery, Page page) {

		if(null == attendanceRecordQuery.getProjectId()){
			log.info("参数错误，缺少projectId");
			return page;
		}
		if(null == attendanceRecordQuery.getIndustryEnum()){
			log.info("参数错误，缺少industryId");
			return page;
		}
		AttendanceQuery attendanceQuery = new AttendanceQuery();
		if(null != attendanceRecordQuery.getStartTime()){
			attendanceQuery.setStartTime(attendanceRecordQuery.getStartTime());
		}
		if(null != attendanceRecordQuery.getEndTime()){
			attendanceQuery.setEndTime(attendanceRecordQuery.getEndTime());
		}
		attendanceQuery.setOffset(((int)page.getSize() * ((int)page.getCurrent()-1)));
		attendanceQuery.setLimit((int) page.getSize());
		ResultJson<Page<AttendanceRecord>> listResultJson = attendanceApi.recordList(attendanceRecordQuery.getIndustryEnum(), attendanceRecordQuery.getProjectId(), attendanceQuery);

		if(listResultJson.isState()){
			return listResultJson.getResult();
		}else{
			log.error("考勤记录获取失败");
		}
		return page;
	}
}
